package study.proxy.myproxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyMethodProxy implements  MyInvocationHandler{

    private Object proxyObject;

    public Object newInstance(Object proxyObject) throws  Exception{
        this.proxyObject = proxyObject;
        Class<?> aClass = proxyObject.getClass();

        return  MyProxy.newProxyInstance(new MyClassLoader(),this ,aClass.getInterfaces());
    }

    @Override
    public Object invoke(Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {

        begin();

        Object  invoke = method.invoke(proxyObject, args);


        after();



        return invoke;
    }

    private void after() {
        System.out.println("动态代理执行后。。。。。。");

    }

    private void begin() {
        System.out.println("动态代理执行前。。。。。。");
    }


}
